package org.liang.factory.bean;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/*
 * javabean基本信息
 */
public class BeanInfo implements Cloneable{
	private String className;//类名
	private String classComment="";//类注释
	private String author;//作者
	private String classPackage;//包
	private String classPath;//类路径
	public boolean cover = false;//是否覆盖已经存在的文件，默认不覆盖，如果存在跳过
	private List<BeanAttrsInfo> attrList;//属性列表
	
	private Set<String> importPackage;//导入包
	
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public String getClassComment() {
		return classComment;
	}
	public void setClassComment(String classComment) {
		this.classComment = classComment;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getClassPackage() {
		return classPackage;
	}
	public void setClassPackage(String classPackage) {
		this.classPackage = classPackage;
	}
	public String getClassPath() {
		return classPath;
	}
	public void setClassPath(String classPath) {
		this.classPath = classPath;
	}
	public List<BeanAttrsInfo> getAttrList() {
		return attrList;
	}
	public void setAttrList(List<BeanAttrsInfo> attrList) {
		this.attrList = attrList;
	}
	public Set<String> getImportPackage() {
		return importPackage;
	}
	public void setImportPackage(Set<String> importPackage) {
		this.importPackage = importPackage;
	}
	
	@Override
	public BeanInfo clone()  {
		BeanInfo beanInfo=null;
		try {
			beanInfo = (BeanInfo) super.clone();
			if(this.attrList != null && this.attrList.size() > 0) {
				List<BeanAttrsInfo> copy = new ArrayList<BeanAttrsInfo>();
				for (BeanAttrsInfo beanAttrsInfo : this.attrList) {
					copy.add(beanAttrsInfo.clone());
				}
				beanInfo.setAttrList(copy);
			}
			if(this.importPackage.size() > 0) {
				Set<String> newCopy = new HashSet<String>();
				Iterator<String> it =  this.importPackage.iterator();
				while(it.hasNext()) {
					newCopy.add(it.next());
				}
				beanInfo.setImportPackage(newCopy);
			}
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return beanInfo;
	}
}
